package cgl.hadoopsensorgrid.sensorgrid.util;

import java.io.IOException;

/**
 * 
 * executeCommand class executes a command line.
 * 
 * @author Chao Sun
 * 
 */
public class executeCommand {
	
	/**
	 * Constructor.
	 */
	public executeCommand() {
	}
	
	public static void execute(String command) {
		Runtime runtime = Runtime.getRuntime();
		try {
			String osname = System.getProperty("os.name");
			String[] args = null;
			if (osname.equals("Linux")) {
				args = new String[] { "sh", "-c", command };
			} else if (osname.substring(0, 3).equals("Win")) {
				args = new String[] { "cmd", "/c", command };
			} else {
				System.out.println("Cannot execute the command");
				System.exit(0);
			}
			Process proc = runtime.exec(args);
		} catch (IOException e) {
			System.out.println("Exec error: " + e.getMessage());
			e.printStackTrace();
		}
	}
	
}